Repository navigation
feat: detect contract drift and serve the latest virtually - #93
Conversation
There was a problem hiding this comment.
Independent review (diff read before description; task #85's agreed design — virtual _latest, no shadow file, never overwrite — checked against the implementation; head extracted clean into an isolated workspace, go test ./... green, plus my own experiments below).
Verified, by experiment where it mattered:
- Stamp round-trips. Beyond the PR's own tests (fakeContracts), I scaffolded the real embedded contracts into a temp dir: zero drift; and hub-style unstamped copies of the same contracts: zero drift. Live:
initin a fresh git dir writes stamped contracts (<!-- scaffolded by codecrew dev; upstream: … -->), androles diff reviewerimmediately reports "matches the embedded dev contract". - stripStamp is safe on the edges. Exercised: unstamped content (this hub's committed
roles/— passes through byte-identical), hand-reworded stamp keeping the prefix (strips), malformed stamp with no-->close (passes through unchanged rather than eating content), contract text containing-->after the stamp (only the stamp is cut), empty file, stamp-only file. All behave. - The LCS diff is correct. 2000-case reconstruction fuzz in my workspace: for random line sequences (including empty lines and
-->/<!--lines), the-/context lines always reconstruct the local side exactly and the+/context lines the embedded side exactly, and no unmarked lines ever appear. Live output in the temp hub reads correctly (local edit shows as-, reconciliation line closes the diff). - status behavior, live both ways. In this hub (clean): no drift lines — silent. In a temp hub with an edited
roles/qa.mdand origin pointed at the hub: exactly one line,contract drift: roles/qa.md differs from the embedded dev contract — codecrew roles diff qa, one per drifted role by construction. Spokes: noroles/dir means every comparison skips (test covers it;contractDrifttreats a missing local file as not-drift). - Nothing writes into
roles/. No write/create/mkdir calls anywhere in roles.go or status.go; the only writer remainsscaffold(), whose kept-if-present skip (os.Stat→ skipped) is unchanged — an existing hub's contracts are never touched, stamped, or overwritten.roles show --latestmaterializes the embedded contract to stdout only — the virtual_latestof the design of record, and its output is byte-identical to the branch'sroles/qa.mdsource (verified withdiff). - Surface complete per plan step 5: dispatch + usage text, SPEC §6 verb row, init row stamp note, AGENTS.md scaffold reconciliation bullet (addressed to the coordination layer, "never overwrite blindly"). Merge-simulated against PR #92: clean.
Non-blocking notes: roles show <role> --latest requires running inside a codecrew project (config.Load runs before the subverb switch) though it only reads the embed — mild ergonomics, defensible. unifiedDiff renders an empty side as one spurious - marker (Split of "" yields [""]) — reachable only for an empty contract file, cosmetic. The drift report rides at the end of status, so it is not shown when the network half of status fails first — consistent with the plan's "no network beyond what status already does".
Approved.
Closes #85.
Delivers the contract-propagation design agreed with the operator (2026-08-25) — the virtual
_latest, superseding a physical shadow file (rejected for authority confusion, side-effect writes, and messenger staleness). The current contract always rides the installed binary; everything else follows from that.initnow writes each contract with<!-- scaffolded by codecrew <version>; upstream: radiusred/gh-codecrew roles/<name> -->— the base for a later three-way judgment is fetchable from the upstream repo at the stamped release.stripStampremoves exactly the stamp, so comparisons see the contract alone; unstamped files (this hub's ownroles/) pass through whole.status: purely local comparison of eachroles/file (stamp-stripped) against the embedded copy; differing roles are reported with a pointer atcodecrew roles diff <role>. Spokes (noroles/) report nothing.roles diff <role>— minimal LCS line diff, local (−) vs embedded (+), closing with the reconciliation rule: contracts are the project's fork, reconcile through a task and PR, never a blind overwrite.roles show <role> --latestprints the embedded contract whole: the_latestfile, materialized only when a decision is being made.initrow notes the stamp.Tests per #46: stamp round-trip, fresh-scaffold-zero-drift (proves the stamp strips cleanly), local-edit drift, spoke skip, diff algorithm, diff/show output and error paths. Live smoke: this hub reports zero drift against its own source-built binary;
statusstays silent when clean.